home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Graphs / sa / edges < prev    next >
Text File  |  1996-07-18  |  3KB  |  92 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Edges for the graph classes
  3. -- Author: Benedict A. Gomes <gomes@tiramisu.ICSI.Berkeley.EDU>
  4. -- Copyright (C) 1995, International Computer Science Institute
  5. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  6. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  7. -- LICENSE contained in the file: Sather/Doc/License of the
  8. -- Sather distribution. The license is also available from ICSI,
  9. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  10. -------------------------------------------------------------------
  11. abstract class $EDGE{NTP} < $STR is
  12.    first: NTP;
  13.    second: NTP;
  14. end;
  15. -------------------------------------------------------------------
  16. class UEDGE{NTP} < $EDGE{NTP}, $HASH is
  17.    -- Undirected edge
  18.    include COMPARABLE;
  19.    private include COMPARE{NTP};
  20.    
  21.    readonly attr first, second: NTP;
  22.  
  23.    create(f,s: NTP): SAME is
  24.       res ::= new;  res.first := f; res.second := s; return res;
  25.       --res: SAME;   return(res.first(f).second(s));
  26.    end;
  27.  
  28.    is_eq(e:UEDGE{NTP}): BOOL is
  29.       return (elt_eq(first,e.first) and elt_eq(second, e.second)) or
  30.           (elt_eq(first,e.second) and elt_eq(second, e.first))
  31.    end;
  32.    
  33.    is_reflexive: BOOL is  return elt_eq(first,second);end;
  34.    
  35.    hash:INT is
  36.       -- A simple hash value computed from the hash values of the 
  37.       -- components. For this to work, these must either be value
  38.       -- types which define hash values or reference types.
  39.       h1,h2:INT;
  40.       h1 := elt_hash(first);
  41.       h2 := elt_hash(second);
  42.       return h1.bxor(h2.lshift(2)) 
  43.    end;
  44.    
  45.    str: STR is  return "{"+elt_str(first)+","+elt_str(second)+"}"; end;
  46.    
  47.    elt_str(e: NTP): STR is
  48.       typecase e  when $STR then return e.str else return "first" end;
  49.    end;
  50.  
  51. end;
  52. -------------------------------------------------------------------
  53. class DIEDGE{NTP} < $EDGE{NTP}, $HASH is
  54.    -- Directed edge
  55.    include COMPARABLE;
  56.    include COMPARE{NTP};
  57.    
  58.    readonly attr first, second: NTP;
  59.  
  60.    create(f,s: NTP): SAME is
  61.       res ::= new;  res.first := f; res.second := s; return res;
  62.      -- res: SAME;
  63.       -- return(res.first(f).second(s));
  64.    end;
  65.  
  66.    reverse: DIEDGE{NTP} is  return #(second,first); end;
  67.    
  68.    is_reflexive: BOOL is return elt_eq(first, second) end;
  69.    
  70.    is_eq(e:DIEDGE{NTP}): BOOL is
  71.       return ((elt_eq(first,e.first) and elt_eq(second,e.second)))
  72.    end;
  73.    
  74.    hash:INT is
  75.       -- A simple hash value computed from the hash values of the 
  76.       -- components. For this to work, these must either be value
  77.       -- types which define hash values or reference types.
  78.       h1,h2:INT;
  79.       h1 := elt_hash(first);
  80.       h2 := elt_hash(second);
  81.       return h1.bxor(h2.lshift(2)) 
  82.    end;
  83.  
  84.    str: STR is  return "{"+elt_str(first)+","+elt_str(second)+"}"; end;
  85.    
  86.    elt_str(e: NTP): STR is
  87.       typecase e  when $STR then return e.str else return "first" end;
  88.    end;
  89.  
  90. end;
  91. -------------------------------------------------------------------
  92.